package cn.com.taurus.controller.datatable;

import cn.com.taurus.bean.AutomaticPlanMessageBean;
import cn.com.taurus.bean.FundAndFundTypeBean;
import cn.com.taurus.biz.AutomaticPlanMessageBiz;
import cn.com.taurus.biz.FundAndFundTypeBiz;
import cn.com.taurus.entity.AutomaticPlanMessage;
import cn.com.taurus.util.Log;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
public class AutomaticController {
    @Autowired
    AutomaticPlanMessageBiz automaticPlanMessageBiz;

    @RequestMapping("/automatic")
    public String fundAndFundType() {
        return "datatable/automatic";
    }

    /**
     * 修改定投
     * @param automaticPlanMessage
     * @return
     */
    @RequestMapping("/updateAutomatic")
    @Log(operation = "修改定投信息",type = 2)
    public String updateAutomatic(@ModelAttribute AutomaticPlanMessage automaticPlanMessage){
        automaticPlanMessageBiz.updateAutomaticPlanMessageByObject(automaticPlanMessage);
        return "datatable/automatic";
    }

    /**
     * 删除定投
     * @param apmId
     * @return
     */
    @RequestMapping("/deleteAutomatic")
    @Log(operation = "删除定投信息",type = 3)
    public String deleteAutomatic(Integer apmId){
        automaticPlanMessageBiz.deleteAutomaticPlanMessageByApmId(apmId);
        return "datatable/automatic";
    }

    /**
     * 模糊查询
     * @param pageNum 几条
     * @param pageSize 数量
     * @return
     */
    @ResponseBody
    @RequestMapping("/conditionSelectAutomaticPlanMessage")
    @Log(operation = "条件查询定投信息",type = 4)
    public HashMap conditionSelectAutomaticPlanMessage(Integer pageNum, Integer pageSize, AutomaticPlanMessageBean automaticPlanMessageBean){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<AutomaticPlanMessage> rule = automaticPlanMessageBiz.conditionSelectAutomaticPlanMessage(automaticPlanMessageBean);
        PageInfo<AutomaticPlanMessage> pageInfo = new PageInfo<>(rule);

        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());

        return map;
    }

    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectAutomatic")
    public HashMap selectAutomatic(Integer pageNum,Integer pageSize){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<AutomaticPlanMessage> rule = automaticPlanMessageBiz.queryAllAutomaticPlanMessage();
        PageInfo<AutomaticPlanMessage> pageInfo = new PageInfo<>(rule);

        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());

        return map;
    }
}
